package com.nd.qa.shareplate.dom4j;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class DOM4JQueryDemo {

	public static void main(String[] args) {
		
		try {
			File file = new File("E:\\baiduyun\\parse.txt");
			SAXReader reader = new SAXReader();
			//获取根节点
			Document classElement = reader.read(file);
			//获取子节点
			List<Node> nodes = classElement.selectNodes("/class/student[@rollno='493']");
			for (Node node : nodes) {
				System.out.println("\nCurrent Element :" 
			               + node.getName());
			            System.out.println("Student roll no : " 
			               + node.valueOf("@rollno") );
			            System.out.println("First Name : " + node.selectSingleNode("firstname").getText());
			            System.out.println("Last Name : " + node.selectSingleNode("lastname").getText());
			            System.out.println("First Name : " + node.selectSingleNode("nickname").getText());
			            System.out.println("Marks : " + node.selectSingleNode("marks").getText());
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
